import * as API from "@/api/axios";
import * as util from "@/common/util";

export default {

    //优惠码-获取列表
    getPage: (params, page) => {
        const url = util.replacePageNumAndSize(`/manage/promo-codes/{pageNum}/{pageSize}`, page)
        return API.axiosGetAPI(url, params)
    },

    // 优惠码-获取优惠券编辑信息
    getEditDetail: id => {
        return API.axiosGetAPI(`/manage/promo-codes/${id}`)
    },


    // 优惠码-获取优惠码详情
    getDetail: id => {
        return API.axiosGetAPI(`/manage/promo-codes/detail/${id}`)
    },

    // 优惠码-获取优惠码兑换记录
    getCouponsRecord: (id, page) => {
        const url = util.replacePageNumAndSize(`/manage/promo-codes/${id}/usage/{pageNum}/{pageSize}`, page)
        return API.axiosGetAPI(url)
    },

    // 优惠券-新增优惠券
    addCoupon: (params) => {
        const url = '/manage/promo-codes'
        const headers = {
            'lang-key': params.id ? 'branch_Edit' : 'branch_Create'
        }
        if (params.id) {
            return API.axiosPutAPI(url, params, headers)
        } else {
            return API.axiosPostAPI(url, params, headers)
        }
    },


    // 优惠码-修改状态
    editState: params => {
        const headers = {
            'lang-key': params.state == 0 ? 'Online_coupon' : 'Offline_coupon'
        }
        return API.axiosPutAPI(`/manage/promo-codes/state`, params, headers)
    },

}